switchroot: Ensure /run/ostree-booted is created even without initramfs
authorColin Walters <walters@verbum.org>
Thu, 22 Mar 2018 14:14:22 +0000 (10:14 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 22 Mar 2018 19:02:29 +0000 (19:02 +0000)
See https://mail.gnome.org/archives/ostree-list/2018-March/msg00012.html

If ostree-prepare-root is run as pid 1 (i.e we're not using an initramfs), then
anything we write outside the target sysroot (such as `/run/ostree-booted`) will
be lost.

Since `ostree-remount.service` runs fairly early in boot, and is triggered via
`ConditionKernelCommandLine=ostree`, we can just touch the file there in
addition.

Closes: #1508
Approved by: akiernan

src/switchroot/ostree-mount-util.h
src/switchroot/ostree-prepare-root.c
src/switchroot/ostree-remount.c

index 7cf7e09e1d2cc5b0ebc12706e2c8cf8f96cf37a0..08e10f976b76c94afd4b1f774f221f71632f3377 100644 (file)
@@ -104,4 +104,19 @@ read_proc_cmdline_ostree (void)
   return ret;
 }
 
+/* This is an API for other projects to determine whether or not the
+ * currently running system is ostree-controlled.
+ */
+static inline void
+touch_run_ostree (void)
+{
+  int fd = open ("/run/ostree-booted", O_CREAT | O_WRONLY | O_NOCTTY | O_CLOEXEC, 0640);
+  /* We ignore failures here in case /run isn't mounted...not much we
+   * can do about that, but we don't want to fail.
+   */
+  if (fd == -1)
+    return;
+  (void) close (fd);
+}
+
 #endif /* __OSTREE_MOUNT_UTIL_H_ */
index 0b04189eb599e291f668435b297f4600f4d5c9b5..a5c3c785e70a0c68ad383e163ac4a32134f2341e 100644 (file)
 
 #include "ostree-mount-util.h"
 
-/* This is an API for other projects to determine whether or not the
- * currently running system is ostree-controlled.
- */
-static void
-touch_run_ostree (void)
-{
-  int fd;
-
-  fd = open ("/run/ostree-booted", O_CREAT | O_WRONLY | O_NOCTTY | O_CLOEXEC, 0640);
-  /* We ignore failures here in case /run isn't mounted...not much we
-   * can do about that, but we don't want to fail.
-   */
-  if (fd == -1)
-    return;
-  (void) close (fd);
-}
-
 static char*
 resolve_deploy_path (const char * root_mountpoint)
 {
@@ -205,7 +188,13 @@ main(int argc, char *argv[])
         err (EXIT_FAILURE, "failed to bind mount (class:readonly) /usr");
     }
 
-  touch_run_ostree ();
+
+  /* We only stamp /run now if we're running in an initramfs, i.e. we're
+   * not pid 1.  Otherwise it's handled later via ostree-remount.service.
+   * https://mail.gnome.org/archives/ostree-list/2018-March/msg00012.html
+   */
+  if (getpid () != 1)
+    touch_run_ostree ();
 
   if (strcmp(root_mountpoint, "/") == 0)
     {
index 3644a06358b78cf157f103730db4555c2796f98b..c3e39c0bef79106e892655aad33a88120a8f4c8b 100644 (file)
@@ -46,6 +46,16 @@ main(int argc, char *argv[])
   struct stat stbuf;
   int i;
 
+  /* See comments in ostree-prepare-root.c for this.
+   *
+   * This service is triggered via
+   * ConditionKernelCommandLine=ostree
+   * but it's a lot easier for various bits of userspace to check for
+   * a file versus parsing the kernel cmdline.  So let's ensure
+   * the stamp file is created here too.
+   */
+  touch_run_ostree ();
+
   /* The /sysroot mount needs to be private to avoid having a mount for e.g. /var/cache
    * also propagate to /sysroot/ostree/deploy/$stateroot/var/cache
    *